home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9307 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help -- Problem with Protected Class in Borland 4.5
  5. Date: 29 Feb 1996 22:18:29 GMT
  6. Organization: Technical University of Berlin, Germany
  7. Message-ID: <4h58nl$5hf@news.cs.tu-berlin.de>
  8. NNTP-Posting-Host: 130.149.17.230
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. edfollo@lovage.lerc.nasa.gov (Jeff Follo) writes:
  14. > I'm using Borland C++ 4.5, trying to create either a DOS target or a EasyWin
  15. > target.  I cannot get the following code to compile:
  16. > #include <iostream.h>
  17. > class BaseClass
  18. > {
  19. >    public:
  20. >       int a;
  21. >    protected:
  22. >       int b;
  23. > };
  24. > class UpperClass : public BaseClass
  25. > {
  26. >    public:
  27. >       void print_a() {cout << "\na = " << a;}
  28. >       void print_b() {cout << "\nb = " << b;}
  29. > };
  30. > void main()
  31. > {
  32. >    UpperClass x;
  33. >    x.a = 1;
  34. >    x.b = 2;
  35. >    x.print_a();
  36. >    x.print_b();
  37. > }
  38. > The error I get is:
  39. > 'BaseClass::b' is not accessible in function main()
  40. > The code works if I comment out protected. What's wrong here?
  41.  
  42. You declare b protected in BaseClass and it remains protected in UpperClass.
  43. Logically, it's not accessible in main. Why do you declare b protected if
  44. you want to access it outside the class?
  45.  
  46. Bye
  47.  
  48. Roman
  49.  
  50.